
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3.简单动画-时序动画</title>
    <style>
        .block {
            width: 100px;
            height: 100px;
            top: 100px;
            left: 100px;
            position: absolute;
            background: blue;
        }
    </style>
</head>
<body>
    <div class="block"></div>
    <script>
        const block = document.querySelector('.block');
        const startAngle = 0;
        const T = 2000;
        let startTime = null;
        function update() {
            startTime = startTime == null ? Date.now() : startTime;
            const p = (Date.now() - startTime) / T;
            const angle = startAngle + p * 360;
            block.style.transform = `rotate(${angle}deg)`;
            requestAnimationFrame(update);
        }
        update();
    </script>
</body>
</html>